#include "info.h"

Info::Info()
{
    m_Nom = "" ;
    m_Prenom = "";
    m_Adresse = "";
    m_CodePostal = "";
    m_Ville = "";
    m_TelFixe = "";
    m_TelPortable = "";
    m_Email = "";
}

Info::Info(QString Nom, QString Prenom)
{
    m_Nom = Nom;
    m_Prenom = Prenom;
    m_Adresse = "";
    m_CodePostal = "";
    m_Ville = "";
    m_TelFixe = "";
    m_TelPortable = "";
    m_Email = "";
}
Info::Info(QString Nom, QString Prenom, QString Adresse, QString CodePostal,QString Ville,QString TelFixe,QString TelPortable,QString Email)
{
    m_Nom = Nom;
    m_Prenom = Prenom;
    m_Adresse = Adresse;
    m_CodePostal = CodePostal;
    m_Ville = Ville;
    m_TelFixe = TelFixe;
    m_TelPortable = TelPortable;
    m_Email = Email;
}
Info::Info(QString datas)
{
    QStringList liste = datas.split(SEPARATEUR1);
    m_Nom = liste.at(0);
    m_Prenom = liste.at(1);
    m_Adresse = liste.at(2);
    m_CodePostal = liste.at(3);
    m_Ville = liste.at(4);
    m_TelFixe = liste.at(5);
    m_TelPortable = liste.at(6);
    m_Email = liste.at(7);

}

void Info::setNom(QString Nom)
{
    m_Nom = Nom;
}

void Info::setPrenom(QString Prenom)
{
    m_Prenom = Prenom;
}
 void Info::setAdresse(QString Adresse)
 {
     m_Adresse = Adresse;
 }
bool Info::setCodePostal(QString CodePostal)
{
    if (CodePostal.length() == 5)
    {
    m_CodePostal = CodePostal;
        return true;
    }
    return false;
}
void Info::setVille(QString Ville)
{
    m_Ville = Ville;
}
void Info::setTelFixe(QString TelFixe)
{
    m_TelFixe = TelFixe;
}
void Info::setTelPortable(QString TelPortable)
{
    m_TelPortable = TelPortable;
}
void Info::setEmail(QString Email)
{
    m_Email = Email;
}
QString Info::getNom()const
{
    return m_Nom;
}
QString Info::getPrenom()const
{
    return m_Prenom;
}
QString Info::getAdresse()const
{
    return m_Adresse;
}
QString Info::getCodePostal()const
{
    return m_CodePostal;
}
QString Info::getVille()const
{
    return m_Ville;
}
QString Info::getTelFixe()const
{
    return m_TelFixe;
}
QString Info::getTelPortable()const
{
    return m_TelPortable;
}
QString Info::getEmail()const
{
    return m_Email;
}

QString Info::NomEtPrenom()const
{
    QString strNom = getNom().toLower();
    strNom[0] = strNom.at(0).toUpper();
    QString strPrenom = getPrenom().toLower();
    strPrenom[0] = strPrenom.at(0).toUpper();
    return strNom + VIRGULE + strPrenom;
}
bool Info::operator ==(const Info & info)
{
    return m_Nom == info.m_Nom && m_Prenom == info.m_Prenom && m_Adresse == info.m_Adresse && m_CodePostal == info.m_CodePostal && m_Ville == info.m_Ville && m_TelFixe == info.m_TelFixe && m_TelPortable == info.m_TelPortable && m_Email == info.m_Email;

}
QString Info::InfoToString()const
{
    return (m_Nom + SEPARATEUR1 + m_Prenom + SEPARATEUR1 + m_Adresse + SEPARATEUR1 + m_CodePostal + SEPARATEUR1 + m_Ville + SEPARATEUR1 + m_TelFixe + SEPARATEUR1 + m_TelPortable + SEPARATEUR1 + m_Email);
}

bool Info::StringToInfoTest(QString StringToInfo)
{
    if (StringToInfo.isNull())
    {
        QMessageBox::information(NULL, "Info", "QString Null !");
        return false;
    }

    if (StringToInfo.isEmpty())
    {
        QMessageBox::information(NULL, "Info", "QString Vide !");
        return false;
    }

    QStringList liste = StringToInfo.split(SEPARATEUR1);

    if (liste.count() != 8)
    {
        QMessageBox::information(NULL, "Info", "Pas le bon nombre");
        return false;
    }
    return true;

}

